
/**
 * 影院首页
 */
let sy = new Vue({
    el: '#middle',
    data: {
        films: [],
        user: JSON.parse(sessionStorage.getItem("user")),
        oneFilm:{},
        oneFilmCount:'',
        twoFilm:{},
        twoFilmCount:'',
        threeFilm:{},
        threeFilmCount:'',
        fourFilm:{},
        fourFilmCount:'',
        fiveFilm:{},
        fiveFilmCount:''
    },
    created() {
        $.get('http://localhost:8080/cinema/api/SelectShowsFilmServlet.do', function (dto) {
            sy.films = dto.value;

        });

        $.get('http://localhost:8080/cinema/api/FilmPaiMingServlet.do', function (dto) {
            let formData1 = {
                filmId: dto.value[0].filmId
            }
            $.get('http://localhost:8080/cinema/api/SelectFilmByIdServlet.do', formData1, function (dto1) {
                sy.oneFilm = dto1.value;
            });
            $.get('http://localhost:8080/cinema/api/SelectCountByFilmIdServlet.do', formData1, function (dto11) {
                sy.oneFilmCount = dto11.value;
            });


            let formData2 = {
                filmId: dto.value[1].filmId
            }
            $.get('http://localhost:8080/cinema/api/SelectFilmByIdServlet.do', formData2, function (dto2) {
                sy.twoFilm = dto2.value;
            });
            $.get('http://localhost:8080/cinema/api/SelectCountByFilmIdServlet.do', formData2, function (dto22) {
                sy.twoFilmCount = dto22.value;
            });


            let formData3 = {
                filmId: dto.value[2].filmId
            }
            $.get('http://localhost:8080/cinema/api/SelectFilmByIdServlet.do', formData3, function (dto3) {
                sy.threeFilm = dto3.value;
            });
            $.get('http://localhost:8080/cinema/api/SelectCountByFilmIdServlet.do', formData3, function (dto33) {
                sy.threeFilmCount = dto33.value;
            });


            let formData4 = {
                filmId: dto.value[3].filmId
            }
            $.get('http://localhost:8080/cinema/api/SelectFilmByIdServlet.do', formData4, function (dto4) {
                sy.fourFilm = dto4.value;
            });
            $.get('http://localhost:8080/cinema/api/SelectCountByFilmIdServlet.do', formData4, function (dto44) {
                sy.fourFilmCount = dto44.value;
            });


            let formData5 = {
                filmId: dto.value[4].filmId
            }
            $.get('http://localhost:8080/cinema/api/SelectFilmByIdServlet.do', formData5, function (dto5) {
                sy.fiveFilm = dto5.value;
            });
            $.get('http://localhost:8080/cinema/api/SelectCountByFilmIdServlet.do', formData5, function (dto55) {
                sy.fiveFilmCount = dto55.value;
            });


        });

        // let logWillAddOrder = JSON.parse(localStorage.getItem("LogWillAddOrder"));
        // if (this.user == null || logWillAddOrder == null) {
        //     return;
        // }


        // console.log(logWillAddOrder);


        // // 添加订单前，先查询有没有未付款的订单，如果有，需先删除原先未付款的订单，没有则直接添加
        // $.get('http://localhost:8080/cinema/api/SelectOrderByStatusServlet.do', function (dto) {

        //     if (dto.value != null) {
        //         let formData11 = {
        //             orderId: dto.value.orderId
        //         }
        //         // 发送异步，实现根据订单ID 删除订单
        //         $.ajax({
        //             url: 'http://localhost:8080/cinema/api/DeleteOrderByIdServlet.do',
        //             type: 'delete',
        //             data: JSON.stringify(formData11),
        //             dataType: 'json',
        //             success: function (dto) {
        //                 // 从本地存储取出数据 ，根据循环遍历的座位ID、以及放映ID，来修改座位状态
        //                 let currentSeat = JSON.parse(localStorage.getItem("currentSeat"));
        //                 for (let sid of currentSeat.seatIdarr) {
        //                     let formData22 = {
        //                         seatId: sid,
        //                         showId: currentSeat.showId,
        //                         status: 0
        //                     }

        //                     // 发送异步，实现根据放映ID、座位ID 修改放映场次对应影厅的座位状态
        //                     $.ajax({
        //                         url: 'http://localhost:8080/cinema/api/UpdateSeatStatusByIdServlet.do',
        //                         type: 'put',
        //                         data: JSON.stringify(formData22),
        //                         dataType: 'json',
        //                         success: function (dto) {

        //                         }

        //                     });
        //                 }
        //             }

        //         });
        //     }


        //     let formData1 = {
        //         filmName: logWillAddOrder.filmName,
        //         hallName: logWillAddOrder.hallName,
        //         showDate: logWillAddOrder.showDate,
        //         startTime: logWillAddOrder.startTime,
        //         price: logWillAddOrder.price,
        //         showId: logWillAddOrder.showId,
        //         filmId: logWillAddOrder.filmId,
        //         userId: sy.user.userId,
        //         place: logWillAddOrder.place
        //     }

        //     $.get('http://localhost:8080/cinema/api/OrderAddServlet.do', formData1, function (dto) {
        //         console.log(dto.value);
        //         // 根据循环遍历的座位ID、以及放映ID，来修改座位状态
        //         for (let sid of logWillAddOrder.seatIdarr) {
        //             let formData2 = {
        //                 seatId: sid,
        //                 showId: logWillAddOrder.showId,
        //                 status: 2
        //             }

        //             // 发送异步，实现根据放映ID、座位ID 修改放映场次对应影厅的座位状态
        //             $.ajax({
        //                 url: 'http://localhost:8080/cinema/api/UpdateSeatStatusByIdServlet.do',
        //                 type: 'put',
        //                 data: JSON.stringify(formData2),
        //                 dataType: 'json',
        //                 success: function (dto) {
        //                     console.log("修改座位状态成功");
        //                 }

        //             });
        //         }

        //         // 再将用户选中座位对应的座位ID，以及本场次的放映ID，存进本地存储中，用于后面修改座位状态的操作
        //         let formData3 = {
        //             seatIdarr: logWillAddOrder.seatIdarr,
        //             showId: logWillAddOrder.showId
        //         }
        //         localStorage.setItem("currentSeat", JSON.stringify(formData3));
        //         localStorage.setItem("orderId", dto.value);

        //         localStorage.removeItem("LogWillAddOrder");
        //         $.cookie("djsendtime", null);
        //         LockButton('#Time', 120);

        //     }, "json");
        // }, "json");
    },
    methods: {
        buy:function(id){
            // 设置本地存储数据
            localStorage.setItem("filmId", id);
            // 跳转到新页面，并且是在新窗口中打开
            window.open("home_filmInfo.html");
        }
    }
});


















